namespace CSharpPro._1013;

//1013作业七
public class User
{
    public string Username { get; set; }
    public string Password { get; set; }
    
    public static bool IsValidUsername(string username)
    {
        if (string.IsNullOrWhiteSpace(username))
            return false;
        
        if (username.Length < 3 || username.Length > 15)
            return false;
        
        foreach (char c in username)
        {
            if (!char.IsLetterOrDigit(c) && c != '_')
                return false;
        }
        return true;
    }
    
    public static bool IsValidPassword(string password)
    {
        if (string.IsNullOrWhiteSpace(password))
            return false;
        
        if (password.Length < 6 || password.Length > 20)
            return false;

        bool hasUpper = false;
        bool hasLower = false;
        bool hasDigit = false;
        
        foreach (char c in password)
        {
            if (char.IsUpper(c)) hasUpper = true;
            if (char.IsLower(c)) hasLower = true;
            if (char.IsDigit(c)) hasDigit = true;
        }

        return hasUpper && hasLower && hasDigit;
    }
}